package com.example.springboottestgit.controller;

import com.example.springboottestgit.service.ElasticSearchClientServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @description:
 * @author: ZZZ
 */
@RestController
@RequestMapping("/es")
public class TestController {

    @Autowired
    private ElasticSearchClientServer es;


    //创建索引
    @GetMapping("/create")
    public void createIndex(String indexName) throws IOException {
        es.createIndex(indexName);
    }

    @GetMapping("/create2")
    public void createIndexContent(String indexName, String filePath) throws Exception {
        filePath = "C:\\Users\\user\\Desktop\\测试2\\91055d05c2a14f50890df01f06d83875-招标\\商务文件-拆分后.txt";
        //es.createIndexContent(indexName, filePath);

    }

    @GetMapping("/exists")
    public boolean existsTest(String indexName) throws IOException {
        return es.existsTest(indexName);
    }

    @GetMapping("/delete")
    public boolean deleteTest(String indexName) throws IOException {
        return es.deleteTest(indexName);
    }

    @GetMapping("/query")
    public String queryContent(String indexName, String searchContent, int size) throws IOException {
        return es.queryContent(indexName, searchContent, size);
    }
}
